<template>
  <div>
    <el-row>
      <el-col :span="24" style="text-align: right;">
        <el-input v-model="input" placeholder="请输入查询内容" style="width: 200px; margin-right: 10px;" clearable></el-input>
        <el-button type="primary" @click="chaxun()" style="margin-bottom: 10px;">查询</el-button>
      </el-col>
    </el-row>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="sid" label="就诊编号" width="80px" header-align="center" align="center"></el-table-column>
      <el-table-column prop="pname" label="病人姓名" width="100px" header-align="center" align="center"></el-table-column>
      <el-table-column prop="psex" label="病人性别" width="100px" header-align="center" align="center"></el-table-column>
      <el-table-column prop="patbir" label="出生日期" width="100px" header-align="center" align="center"></el-table-column>
      <el-table-column prop="phone" label="联系方式" width="132px" header-align="center" align="center"></el-table-column>
      <el-table-column prop="identify" label="病人身份证" width="386px" header-align="center"
        align="center"></el-table-column>
      <el-table-column prop="date" label="就诊日期" width="210px" header-align="center"></el-table-column>
      <el-table-column label="操作" width="200px" header-align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="openVisitDialog(scope.row.sid)">就诊</el-button>
          <el-button type="info" size="mini" @click="dialogTableVisible = true; chakan(scope.row.sid)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
      :current-page="pageInfo.pageNum" :page-sizes="[5, 10, 15, 20]" :page-size="pageInfo.pageSize"
      layout="total, sizes, prev, pager, next, jumper" :total="pageInfo.total">
    </el-pagination>

    <el-dialog title="就诊" :visible.sync="visitDialogVisible">
      <el-form :model="visitForm">
        <el-form-item label="症状" label-width="100px">
          <el-input v-model="visitForm.sympotm" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="是否住院" label-width="100px">
          <el-radio-group v-model="visitForm.inhosp">
            <el-radio label="是"></el-radio>
            <el-radio label="否"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="解决方案" label-width="100px">
          <el-input v-model="visitForm.project" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="visitDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitVisit(); addchufang();">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="病情详情" :visible.sync="dialogTableVisible">
      <el-table :data="gridData">
        <el-table-column v-model="gridData.sympotm" prop="sympotm" label="症状" width="150"></el-table-column>
        <el-table-column v-model="gridData.inhosp" prop="inhosp" label="是否住院" width="200"></el-table-column>
        <el-table-column v-model="gridData.project" prop="project" label="解决方案"></el-table-column>
      </el-table>
    </el-dialog>
  </div>

</template>

<script>
import axios from 'axios';

export default {
  data() {
    return {
      input: '',
      tableData: [],
      dialogTableVisible: false,
      gridData: [{
        sympotm: '',
        inhosp: '',
        project: ''
      }],
      visitDialogVisible: false,
      visitForm: {
        sympotm: '',
        inhosp: '',
        project: ''
      },
      pageInfo: {
        pageNum: 1,
        pageSize: 5
      },
    };
  },
  methods: {
    shanchu(){
      this.$axios.delete("/seeadoctor/delete?sid=" + this.visitForm.sid)
      .then((result) => {
        let data = result.data;
        if(data.code == 200){
          this.$message.success("就诊删除成功");
        }
      }).catch((error) => {
        console.error(error);
        this.$message.error("就诊删除失败");
      })
    },
    addchufang() {
      this.$axios.post("/prescription/addchufang", this.visitForm)
        .then((result) => {
          let data = result.data;
          if (data.code == 200) {
            this.$message.success("处方添加成功");
            this.visitDialogVisible = false
          }
        }).catch((error) => {
          console.error(error);
          this.$message.error("处方添加失败");
        })
    },
    handleSizeChange(val) {
      this.pageInfo.pageSize = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.pageInfo.pageNum = val;
      this.list();
    },
    submitVisit() {
      this.$axios.post("/seeadoctor/visit", this.visitForm)
        .then((result) => {
          let data = result.data;
          this.list();
          if (data.code == 200) {
            this.$message.success("就诊信息提交成功");
            this.visitDialogVisible = false;
            this.visitForm = {};
          }
        }).catch((error) => {
          console.error(error);
          this.$message.error("就诊信息提交失败");
        });
    },
    openVisitDialog(sid) {
      this.visitForm.sid = sid;
      this.visitDialogVisible = true;
    },
    chakan(sid) {
      this.$axios.get("/seeadoctor/findById?sid=" + sid)
        .then((result) => {
          let data = result.data;
          if (data.code == 200) {
            this.gridData = data.data;
          }
        }).catch((error) => {
          console.error(error);
        });

    },
    chaxun(input) {
      this.$axios.get("/seeadoctor/findByName?input=" + this.input)
        .then((result) => {
          let data = result.data;
          if (data.code == 200) {
            this.tableData = data.data;
          }
        }).catch((err) => {
          console.log(err);
        });

    },
    list(){
      axios.get('/seeadoctor/findByzhenduan?pageNum=' + this.pageInfo.pageNum + '&pageSize=' + this.pageInfo.pageSize)
        .then((result) =>{
          let data = result.data;
          if(data.code == 200){
            this.tableData = data.data.list;
            this.pageInfo= data.data;
          }
        }).catch((error) =>{
          console.error(error);
        });
    },
  },
  mounted() {
    this.list();
  },
};
</script>

<style scoped>
/* 你可以在这里添加一些样式 */
</style>